package io.renren.modules.business.service.impl;

import io.renren.modules.business.dao.BusProjectDao;
import io.renren.modules.business.entity.BusProjectEntity;
import io.renren.modules.business.service.BusProjectService;
import io.renren.modules.business.util.PageLastUtil;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;


@Service("busProjectService")
public class BusProjectServiceImpl extends ServiceImpl<BusProjectDao, BusProjectEntity> implements BusProjectService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String projectName = (String) params.get("key");
        List<Map<String, Object>> list;
        if (!"".equals(projectName) && projectName.length()!=0) {
            //关键字查询
            list = baseMapper.projectKeyList(projectName);
            list.addAll(baseMapper.projectTeamKeyList(projectName));
        }else {
            //查询列表
            list = baseMapper.projectList();
            list.addAll(baseMapper.projectTeamList());
        }
        return PageLastUtil.getPageUtils(params, list);
    }

    @Override
    public List<Map<String, Object>> queryPageById(Long id) {
        List<Map<String, Object>> list = baseMapper.projectIdList(id);
        return list;
    }

    /**
     * 修改项目信息
     * @param busProeject
     * @return
     */
    @Override
    public boolean updateProject(BusProjectEntity busProeject) {
        Double score = busProeject.getProjectScore() * 20;
        busProeject.setProjectScore(score);
        if (busProeject.getStatusId() == 4) {
            //修改项目信息并为完结项目打分
            baseMapper.updateProject(busProeject.getId(), busProeject.getProjectName(), busProeject.getProjectTutor(),
                    busProeject.getTeamId(), busProeject.getStatusId(), busProeject.getProjectScore());
        }else {
            //修改项目信息
            baseMapper.updateProject(busProeject.getId(), busProeject.getProjectName(), busProeject.getProjectTutor(),
                    busProeject.getTeamId(), busProeject.getStatusId(), 0.0);
        }
        return false;
    }

}